<template>
  <div>  
      <!-- <Button type="info" size="small" @click="playVoice()">播放</Button
                > -->
		<div id="bdtts_div_id" class='voice'>
			<!-- <audio id="tts_autio_id" >
				<source id="tts_source_id" :src="warnVoice" type="audio/mpeg">
				<embed id="tts_embed_id" height="0" width="0" src="">
			</audio> -->
            <audio id="audio_road">
				<source id="audio_road_source" :src="reportVoice" type="audio/mpeg">
				<embed id="audio_road_embed" height="0" width="0" src="">
			</audio>
		</div>
  </div>
</template>
 
<script>
import constData from "@/util/constData";
export default {
  name: 'voiceBroadcast',
  data () {
    return {
      warnVoice : require('../../assets/voice/jingbao.mp3'),//警报声音
      reportVoice : "../../assets/voice/road8_person.mp3",//提示声音,
      reportVoiceList:constData.reportVoiceList,
      playCnt: 0 ,//播放次数统计
      roadAudio: ''
    }
  },
  methods: {
	    playVoice(eventItem){
            console.log("in play")
            let road = eventItem[0]['road_name']
            let event = eventItem[0]['event']
            console.log('road:',road,'event:',event)
            this.reportVoice = require('../../assets/voice/'+this.reportVoiceList[road][event]+'.mp3')
            // let ttsAudio = document.getElementById('tts_autio_id');
            // ttsAudio.volume = 0.3;
            // ttsAudio.playbackRate = 0.9;
            // ttsAudio.play();

            this.roadAudio = document.getElementById('audio_road');
            this.roadAudio.src = this.reportVoice
			this.roadAudio.volume = 1.0;
			this.roadAudio.playbackRate =0.7
			this.playCnt = 0
			this.roadAudio.addEventListener("ended",this.rePlay);
            this.roadAudio.play();
            
        },
        stopVoice(){
            console.log("in stop")
            // let ttsAudio = document.getElementById('tts_autio_id');
            // ttsAudio.pause();
            this.roadAudio = document.getElementById('audio_road');
            this.roadAudio.pause();
        },
        //播放次数
	    rePlay(){
            this.playCnt++;
            // alert(start);
            if(this.playCnt<3){
                this.roadAudio.play();
            }
            }
  }
}
</script>
<style lang="less">
.voice{
    height:0px;
    width:0px;
    position:absolute;
}
</style>